package cn.tedu.store.product.webapi.controller;

import cn.tedu.store.commons.pojo.product.dto.AlbumAddNewDTO;
import cn.tedu.store.commons.pojo.product.dto.AlbumUpdateDTO;
import cn.tedu.store.commons.pojo.product.vo.AlbumListItemVO;
import cn.tedu.store.product.service.IAlbumService;
import cn.tedu.store.commons.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 相册请求处理器
 *
 * @author RelentlessFlow
 * @version 0.0.1
 */
@Api(tags = "01. 相册管理")
@Slf4j
@Validated
@RestController
@RequestMapping("/albums")
public class AlbumController {

    @Autowired
    IAlbumService albumService;

    @ApiOperation("添加相册")
    @ApiOperationSupport(order = 100)
    @PostMapping("/add-new")
    public JsonResult<Void> addNew(@Validated AlbumAddNewDTO albumAddNewDTO) {
        log.debug("开始处理添加相册的请求: 参数:{}", albumAddNewDTO);
        albumService.addNew(albumAddNewDTO);
        log.debug("添加相册成功!");
        return JsonResult.ok();
    }

    @ApiOperation("删除相册")
    @ApiOperationSupport(order = 200)
    @ApiImplicitParam(name = "id", value = "相册id", required = true, dataType = "long")
    @PostMapping("/{id:[0-9]+}/delete")
    public JsonResult<Void> delete(@PathVariable Long id) {
        log.debug("开始处理[删除相册]的请求 参数:{}", id);
        albumService.delete(id);
        log.debug("删除相册成功!");
        return JsonResult.ok();
    }

    @ApiOperation("修改相册")
    @ApiOperationSupport(order = 300)
    @ApiImplicitParam(name = "id", value = "相册id", required = true, dataType = "long")
    @PostMapping("/{id:[0-9]+}/update")
    public JsonResult<Void> update(@PathVariable Long id , AlbumUpdateDTO albumUpdateDTO) {
        log.debug("处理[修改相册]请求 参数:{},{}", id, albumUpdateDTO);
        albumService.update(id, albumUpdateDTO);
        return JsonResult.ok();
    }

    @ApiOperation("相册列表")
    @ApiOperationSupport(order = 400)
    @GetMapping("")
    public JsonResult<List<AlbumListItemVO>> list() {
        log.debug("开始处理[获取相册列表]请求 参数:无");
        return JsonResult.ok(albumService.list());
    }
}
